package com.fly.studio.home.app.service.impl;

import com.fly.studio.home.app.component.BaseContext;
import com.fly.studio.home.app.response.vo.FloorVO;
import com.fly.studio.home.app.response.vo.HomePageVO;
import com.fly.studio.home.app.service.HomePageService;
import com.fly.studio.home.app.arrange.core.ComponentArrange;
import com.fly.studio.home.app.request.HomePageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;

import javax.annotation.Resource;
import java.util.List;

/**
 * Home Page Service
 *
 * @author fuliying3
 * @date 2022/08/23 16:29:00
 */
@Slf4j
@Service
public class HomePageServiceImpl implements HomePageService {

    @Resource
    private ComponentArrange componentArrange;

    /**
     * Home Page
     *
     * @param request {@link HomePageRequest}
     * @return {@link HomePageVO}
     */
    @Override
    public HomePageVO homePage(HomePageRequest request) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("HomePage");
        BaseContext context = new BaseContext();
        context.setRequest(request);
        componentArrange.arrange(context);
        List<FloorVO> floorList = context.getFloor();
        HomePageVO result = new HomePageVO();
        result.setFloorList(floorList);
        stopWatch.stop();
        log.info("HomePageServiceImpl homePage useTime -> {} ms", stopWatch.getTotalTimeMillis());
        return result;
    }
}
